package cn.tedu.learn.tea.domain.common.exception;

import cn.tedu.learn.tea.domain.response.StatusCode;
import lombok.Getter;

/**
 * 自定义业务异常
 */
@Getter
public class BusinessException extends RuntimeException{

    private Integer code;

    private String msg;

    // 手动设置异常
    public BusinessException(StatusCode statusCode, String message) {
        super(message);
        // 状态码
        this.code = statusCode.getCode();
        // 状态码配套的msg
        this.msg = statusCode.getMsg();
    }

    public BusinessException(StatusCode statusCode) {
        // 状态码
        this.code = statusCode.getCode();
        // 状态码配套的msg
        this.msg = statusCode.getMsg();
    }

    // 默认异常使用APP_ERROR状态码
    public BusinessException(String message) {
        super(message);
        this.code = StatusCode.APP_ERROR.getCode();
        this.msg = StatusCode.APP_ERROR.getMsg();
    }

}
